import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
// 框架外路由
import outside from './outside';
// 框架内路由
import within from './within';

const routes: Array<RouteRecordRaw> = [
  ...within, ...outside,
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
// 前置路由守卫
router.beforeEach((to, from, next) => {
  // to 目标路由
  // from 来源
  // next 放行
  if (localStorage.getItem('token') || to.path === '/login') {
    next();
  } else {
    // 拦截路由
    router.push('/login');
  }
});

export default router;
